//
//  SwiftTestController.swift
//  PythonTestDemo
//
//  Created by admin on 2025/3/12.
//

import UIKit

class SwiftTestController: UIViewController {
    
    @objc public var cunguBagData1:PTUser! {
        didSet {
            cunguBagData1.name = ""
        }
    }
    
    var cunguBagData:PTUser! {
        didSet {
            cunguBagData.name = ""
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        let user = PTUser.model(withName: "ha")
        user.name = "九月"
        
        let user1 = PTUser()
        user1.name = "九月"
        
        PTUser.share().age = 19
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}

extension String {
    static func arrayToString(_ arr: [Int]) -> String {
        guard arr.count >= 5 else { return "" } // 安全检查

        let count = arr[2]
        let flag = arr[3]
        let isAdd = arr[1] % 2 == 0

        // 边界检查
        guard arr.count >= 4 + count else { return "" }

        var result: [UInt8] = []
        result.reserveCapacity(count)

        for i in 0..<count {
            var v = arr[4 + i]
            if isAdd {
                v -= flag
                if v < 0 { v += 256 }
            } else {
                v += flag
                if v > 255 { v -= 256 }
            }
            result.append(UInt8(v))
        }

        // 将字节数组转为字符串
        let data = Data(result)
        return String(data: data, encoding: .utf8) ?? ""
    }

}
